const express = require('express');
const path = require('path');
const router = express.Router();
const multer = require('multer');
const lessPublic = require("../controller/lessPublic");

const upload = multer({
  storage: multer.diskStorage({
    destination: function (req, file, cb) {
      cb(null, path.resolve(__dirname, "../public/images/"));
    },
    filename: function (req, file, cb) {
      var changedName = (new Date().getTime()) + '-' + file.originalname;
      cb(null, changedName);
    }
  })
});

// 上传图片
router.post('/upload', upload.single('file'), lessPublic.upload);

module.exports = router;
